<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <meta name="layout" content="bolao" />
    <g:set var="entityName" value="${message(code: 'bet.label', default: 'Bets')}" />
    <title><g:message code="mybets.label" /></title>
    <script type="text/javascript">
            $(function(){
              $('#bet-tabs').tabs({
                  spinner: '${message(code: 'global.loading', default: 'Loading...')}',
                  load: function(event, ui) {
                      $('a', ui.panel).click(function() {
                          $(ui.panel).load(this.href);
                          return false;
                      });
                  }
               });     
            });
    </script>
  </head>
  <body>
  <div class="body">
    <g:if test="${flash.message}">
      <div class="message">${flash.message}</div>
    </g:if>
    <div id="bet-tabs">
      <ul>
        <li><a href="#tabs-1"><g:message code="mybets.label" /></a></li>
        <li><g:remoteLink controller="bet" action="ajaxGetBetters"><span><g:message code="otherbets.label" default="Other Bets"/></span></g:remoteLink></li>
      </ul>
      <div id="tabs-1">
        <g:if test="${!groups}">
          <g:set var="groupEntityName" value="${message(code: 'group.label', default: 'Group')}" />
          <p><g:message code="default.any.not.found.message" args="[groupEntityName]" /></p>
        </g:if>
        <g:each in="${groups}" status="i" var="group">
          <br/>
          <h3>${message(code:'group.label', default: 'Group')} ${group.name}</h3>
          <div class="list">
            <table class="table center">
              <thead>
                <tr>
                  <th colspan="6" style="text-align: center"><g:message code="mybets.label" /></th>
                  <th colspan="5" style="text-align: center"><g:message code="bet.result.label"/></th>
              </tr>
              </thead>
              <tbody>
              <g:each in="${matches}" status="j" var="match">
                <g:if test="${group == match.team1.group}">
                  <g:set var="curBet" value="${null}" />
                  <g:each in="${bets}" status="b" var="bet">
                    <g:if test="${match == bet.match}">
                      <g:set var="curBet" value="${bet}" />
                    </g:if>
                  </g:each>
                  <tr class="${(j % 2) == 0 ? 'odd' : 'even'}">
                  <g:if test="${curBet != null}">
                    <td width="50px">
                    <g:ifAnyGranted role="ROLE_USER">
                      <g:if test="${match.availableToBet}">
                        <g:link action="edit" id="${curBet.id}"><g:message code="global.update" default="update"/></g:link>
                      </g:if>
                      <g:else>
                         <g:if test="${!match.finished}">
                          <g:message code="match.matchDate.timeover" default="Time Over"/>
                         </g:if>
                      </g:else>
                    </g:ifAnyGranted>
                    <g:if test="${match.finished}">
                     <g:message code="match.finished.label" default="finished"/>
                    </g:if>
                    </td>
                    <td>${curBet?.match?.team1?.name}</td>
                    <td>${curBet?.score1}</td>
                    <td>x</td>
                    <td>${curBet?.score2}</td>
                    <td>${curBet?.match?.team2?.name}</td>
                  </g:if>
                  <g:else>
                    <td width="50px">
                      <g:ifAnyGranted role="ROLE_USER">
                        <g:if test="${match.availableToBet}">
                          <g:link action="create" id="${match?.id}"><g:message code="global.bet" default="Bet"/></g:link>
                        </g:if>
                        <g:else>
                           <g:if test="${!match.finished}">
                            <g:message code="match.matchDate.timeover" default="Time Over"/>
                           </g:if>
                        </g:else>
                      </g:ifAnyGranted>
                      <g:if test="${match.finished}">
                       <g:message code="match.finished.label" default="finished"/>
                      </g:if>
                    </td>
                    <td>${match?.team1?.name}</td>
                    <td>${'__'}</td>
                    <td>x</td>
                    <td>${'__'}</td>
                    <td>${match?.team2?.name}</td>
                  </g:else>
                  <td>${match?.team1?.name}</td>
                  <td>${match?.score1 ?: '__'}</td>
                  <td>x</td>
                  <td>${match?.score2 ?: '__'}</td>
                  <td>${match?.team2?.name}</td>
                  </tr>
                </g:if>
              </g:each>
              </tbody>
            </table>
          </div>
        </g:each>
      </div>
      <div id="tabs-2"></div>
    </div>

  </div>
  <div id="sidebar">
    <div id="ranking" class="boxed">
      <h2><g:message code="ranking"/></h2>
      <div class="content">
        <ol>
          <li><a href="#">Fulano</a> <i>(35)</i></li>
          <li class="active"><a href="#">Cliclano</a> <i>(20)</i></li>
          <li><a href="#">Beltrano</a> <i>(10)</i></li>
        </ol>
      </div>
    </div>
  </div>
</body>
</html>
